<%@page import="locations.model.InstitutionType"%>
<%@page import="locations.dao.InstitutionTypeDAO"%>
<%@page import="locations.dao.DAOFactory"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="google.maps" tagdir="/WEB-INF/tags/googlemaps"%>
<%@ page language="java"%>
<%@ page import="locations.dao.DAOFactory"%>
<%@ page import="locations.dao.InstitutionTypeDAO"%>
<%@ page import="locations.dao.InstitutionResponsibleDAO"%>
<%@ page import="com.opensymphony.xwork2.ActionContext"%>

<%@ page import="locations.model.InstitutionType"%>
<%@ page import="locations.model.InstitutionResponsible"%>
<%@ page import="java.util.Collection"%>
	<%
                DAOFactory factory = new DAOFactory();
                InstitutionTypeDAO institutionTypeDAO = factory.getInstitutionTypeDAO();
                Collection<InstitutionType> institutionTypes = institutionTypeDAO.retrieveAll();
                
                InstitutionResponsibleDAO institutionResponsibleDAO = factory.getInstitutionResponsibleDAO();
                Collection<InstitutionResponsible> institutionResponsibles = institutionResponsibleDAO.retrieveAll();
                
		ActionContext.getContext().put("institutionTypes", institutionTypes);
		ActionContext.getContext().put("institutionResponsibles", institutionResponsibles);
	%>

<div>
    <div class="map-form">
        <s:form action="saveInstitution">
            <s:fielderror />
            <table>
                <tr>
                        <td colspan="2"></td>
                </tr>
                <tr>
                        <td><label><s:property value="getText('global.nombre')" /></label></td>
                        <td><s:hidden name="id" value="%{institution.id}" /> <s:textfield
                                        name="name" label="Nombre" value="%{institution.name}" />
                        </td>
                </tr>
                <tr>
                        <td><label><s:property value="getText('global.mail')" /></label></td>
                        <td><s:textfield name="email" label="Mail"
                                        value="%{institution.email}" /></td>
                </tr>
                <tr>
                        <td><label><s:property value="getText('global.telefono')" /></label></td>
                        <td><s:textfield name="phoneNumbers" label="Telefonos"
                                        value="%{institution.phoneNumbers}" /></td>
                </tr>
                <tr>
                        <td><label><s:property value="getText('institucion.detalle')" /></label></td>
                        <td><s:textfield name="detail" label="Detalle"
                                        value="%{institution.detail}" /></td>
                </tr>
                <tr>
                        <td><label><s:property value="getText('global.pcia')" /></label></td>
                        <td><s:textfield name="location.province"
                                        value="%{institution.location.province}" label="Provincia" /></td>
                </tr>
                <tr>
                        <td><label><s:property value="getText('global.partido')" /></label></td>
                        <td><s:textfield name="location.district"
                                        value="%{institution.location.district}" label="Partido" /></td>
                </tr>
                <tr>
                        <td><label><s:property value="getText('global.ciudad')" /></label></td>
                        <td><s:textfield name="location.city"
                                        value="%{institution.location.city}" label="Ciudad" /></td>
                </tr>
                <tr>
                        <td><label><s:property value="getText('global.calle')" /></label></td>
                        <td><s:textfield name="location.street"
                                        value="%{institution.location.street}" label="calle" /></td>
                </tr>
                <tr>
                        <td><label><s:property value="getText('global.numero')" /></label></td>
                        <td><s:textfield name="location.number"
                                        value="%{institution.location.number}" label="Número" /></td>
                </tr>
                <tr>
                        <td><label><s:property value="getText('global.latitud')" /></label></td>
                        <td><s:textfield id="latitude" name="location.latitude"
                                        value="%{institution.location.latitude}" label="Latitud" /></td>
                </tr>
                <tr>
                        <td><label><s:property value="getText('global.longitud')" /></label></td>
                        <td><s:textfield id="longitude" name="location.longitude"
                                        value="%{institution.location.longitude}" label="Longitud" />
                        </td>
                </tr>
                <tr>
                    <td>
                        <label><s:property value="getText('institucion.responsable')" /></label>
                    </td>
                    <td>
                        <s:select name="responsible.id" list="#institutionResponsibles" listKey="id" value="%{institution.responsible.id}" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label><s:property value="getText('global.tipo')" /></label>
                    </td>
                    <td>
                        <s:select value="institution.type.id" name="type.id" list="%{institutionTypes}" listKey="id" />
                    </td>
                </tr>
            </table>
            <s:submit key="boton.guardar"  />
        </s:form>
    </div>
    <div id="map" class="map"></div>
</div>
<div style="clear: both"></div>

<google.maps:Script />
<s:set var="institution" value="institution" scope="request" />
<google.maps:Map container_id="map"
	latitude="${empty institution.location.latitude ? -34.9212936704915 : institution.location.latitude}"
	longitude="${(empty institution.location.longitude) ? -57.9546511173248 : institution.location.longitude}"
	zoom="13">
	<google.maps:LatLngInputField latitude_id="latitude"
		longitude_id="longitude" />
</google.maps:Map>